#ifndef __UTIL_H__
#define __UTIL_H__

#include "object.h"

/* Turn debugging mode on, at least in the development period */
#define DEBUG

#ifdef DEBUG

/* Where all log should go */
#define LOGFILE "/tmp/fuse-log.txt"

#define debug(...) {\
  FILE *logfile = fopen (LOGFILE, "a+"); \
  fprintf (logfile, __VA_ARGS__); \
  fclose (logfile); }
#else
#define debug(...)
#endif

/* 
  Sanitizes the path (remove /../ etc), and puts it in 
  new_path. It is the responsibility of caller to allocate
  enough memory. Does not check existence. Since we call this
  before every path access, it is perfectly possible to get
  something like /a/somefile/../ translated to /a/
*/
void sanitize_path (const char *path, char *new_path);

/* 
  Manipulates string to find path of parent 
*/
void get_parent (const char *path, char *parent);

/* 
  At least length MAX_FNAME_LEN should be allocated for name.
  Returns the null terminated filename
*/
void get_filename (const char *path, char *name);

/*
  Find's the object-id of object corresponding to PATH
  Returns -1 if path is non-existent
*/
int get_object_id (const char *path, object_id *obj_id);

/*
  Fills the object OBJ corresponding to PATH, with BUF pointing
  to the data buffer (upto a max length of MAX_LENGTH)
  Returns 0 on success, negative otherwise
*/

int get_object_from_path (const char *path, object *obj, 
              int max_length, void *buf);


/*
  Saves the object whose pathname we do know 
*/
int save_object_with_path (const char *path, object *obj);

#endif  /* End of __UTIL_H__ */
